#coding:utf-8
# @Time    : 2018/9/30 3:00
# @Author  : 0x007er
# @File    : ZmapGetResult.py
# @Software: PyCharm
import requests,demjson
servers = requests.get('http://104.168.159.24:5000/servers').json()
downloadlist = []
port = '82'
p = r = s = 0
for server in servers:

    try:
        ip = server[1]
        res = requests.get('http://'+ip+':5000/zmapstatus',timeout=10).text
        j = demjson.decode(res)
        p+=int(j['progress'])
        r+=int(j['recv'])
        s+=float(j['speed'])
        downloadlist.append('http://'+ip+'/zmap/out.txt')
        print server[1],j
    except Exception as e:
        print(e)
print float(int(p))/float(len(servers)),r,s
shellcode = 'cd ~/console/static/\nmkdir temp\ncd temp\n'
for i,url in enumerate(downloadlist):
    shellcode+='wget %s -O %s\n' % (url,str(i)+'.txt')
shellcode+='cat * > %s.txt\nmv %s.txt ../\ncd ..\nrm -rf temp\n' % (port,port)

print shellcode
